// BotQuestionModelFactory.java
package com.agileboot.domain.bot.botQuestion.model;

import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.bot.botQuestion.db.BotQuestionService;
import com.agileboot.domain.bot.botQuestion.db.BotQuestionEntity;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class BotQuestionModelFactory {

    private final BotQuestionService service;

    public BotQuestionModel loadById(Integer id) {
        BotQuestionEntity entity = service.getById(id);
        if (entity == null) {
            throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, id, "问答");
        }
        return new BotQuestionModel(entity, service);
    }

    public BotQuestionModel create() {
        return new BotQuestionModel(service);
    }
}
